home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 18530 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.0 KB  |  66 lines

  1. Path: ix.netcom.com!news
  2. From: Bradd W. Szonye <bradds@ix.netcom.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: RE: int::~int()
  5. Date: 20 Apr 1996 16:36:27 GMT
  6. Organization: Netcom
  7. Message-ID: <01bb2ed7.f7cd64e0$65c2b7c7@Zany.localhost>
  8. References: <317083F7.116E@public.sta.net.cn> <marnoldDpuDu9.D7s@netcom.com>
  9. NNTP-Posting-Host: det-mi3-05.ix.netcom.com
  10. X-NETCOM-Date: Sat Apr 20 11:36:27 AM CDT 1996
  11. X-Newsreader: Microsoft Internet News
  12.  
  13.  
  14. On Sunday, April 14, 1996, Matt Arnold wrote...
  15. > Xu Yifeng <jafd@public.sta.net.cn> writes:
  16. > >Hi everybody,
  17. > >can your compiler compile following program?
  18. > >//------------------------
  19. > >void main()
  20. > >{
  21. > >     int i = 0;
  22. > >     i.int::~int();
  23. > >}
  24. > >//------------------------
  25. > >is it a legal C++ program?
  26. > It's supposed to be, but most C++ compiler's will not compile it.
  27. > In fact, this exact sitution is encountered in the Standard Template
  28. > Library (STL), which contains the following template function...
  29. > template <class T>
  30. > inline void destroy(T* pointer) {
  31. >     pointer->~T();
  32. > }
  33. > ...which is supposed to be used to destroy anything, including an
  34. > instance of an int, just like your sample code wants to.
  35. > To make STL work with current compilers, you'll find it also contains
  36. > work-around versions of destroy().  There's one specifically for int,
  37. > and it looks like this...
  38. > inline void destroy(int*) {}
  39. > ...which is what the template version is supposed to do; nothing.  STL
  40. > contains about 50 or so of these specific versions of destroy() (for
  41. > ints, chars, floats, etc.).
  42. > You sample code is legal as far as the language goes, but probably
  43. > not as far as your compiler is concerned.  Mine, Borland C++ 4.52,
  44. > will not compile it either.  However, I think Borland C++ 5.0 will.
  45.  
  46. This is just another good reason to rely on your compiler's manuals and
  47. observing actual program behavior rather than relying on a standards
  48. document. Especially with an evolving language like C++, you can't always
  49. rely on the standards.
  50.  
  51.  
  52.